package com.atguigu.ssyx.acl.service.impl;

import com.atguigu.ssyx.acl.mapper.RoleMapper;
import com.atguigu.ssyx.acl.mapper.RoleMapper;
import com.atguigu.ssyx.model.acl.Role;
import com.atguigu.ssyx.acl.service.RoleService;
import com.atguigu.ssyx.vo.acl.RoleQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @Description:
 * @Author: Ian
 * @Date: 2023/9/25 14:56
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {


    /**
     * 角色分页查询, like name
     * @param page
     * @param roleQueryVo
     * @return
     */
    @Override
    public IPage queryPageRole(Page page, RoleQueryVo roleQueryVo) {

        // 创建条件对象,封装条件
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();

        // 判断vo里面有没有条件
        if (!StringUtils.isEmpty(roleQueryVo.getRoleName())){

            // roleQueryVo里面的name不为空进行 like
            queryWrapper.like("role_name",roleQueryVo.getRoleName());
        }

        // baseMapper 在ServiceImpl 中已经声明了,可以直接使用
        IPage<Role> page1 = baseMapper.selectPage(page, queryWrapper);

        return page1;
    }


}
